package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.RoleUserDao;
import com.djinfo.work.entity.TbSysRoleUser;
import com.djinfo.work.entity.TbSysRoles;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 角色
 */
@Repository("RoleUserDao")
public class RoleUserDaoImpl extends BaseDaoImpl implements RoleUserDao {
	@Override
	public void save(TbSysRoleUser object) {
		if (object.getPkRoleUserId() == null) {
			super.save(object);
		} else {
			super.update(object);
		}
	}

	@Override
	public void update(TbSysRoleUser object) {
		super.update(object);
	}

	@Override
	public void delete(TbSysRoleUser object) {
		super.delete(object);
	}

	@Override
	public TbSysRoleUser selectOne(TbSysRoleUser object) {
		return (TbSysRoleUser)super.getByPrimaryKey(TbSysRoles.class,object.getPkRoleUserId());
	}

	@Override
	public List<TbSysRoleUser> page(TbSysRoleUser object, Integer pageNum, Integer pageSize) {
		String hql = " from TbSysRoleUser where 1=1 ";
		return (List<TbSysRoleUser>)super.pageQuery( hql,  pageNum,  pageSize);
	}

	@Override
	public Integer getAllRowCount() {
		String hql = "select count(*) from TbSysRoleUser ";
		return super.getUniqueObject(hql).hashCode();
	}

	@Override
	public void deleteUserRoleByRoleId(String roleId) {
		String hql = " delete FROM  TbSysRoleUser where roleId = ? ";
		super.updateByHQL(hql,roleId);
	}

	@Override
	public void deleteUserRoleByUserId(String uid) {
		String hql = " delete FROM  TbSysRoleUser where userId = ? ";
		super.updateByHQL(hql,uid);
	}

	@Override
	public List getRoleUserByUserId(String uid) {
		String hql=" from TbSysRoleUser where userId=?";
		return super.getList(hql,uid);
	}
}

